package com.itheima.a02systeamdemo01;

/***
 *@title SystemDemo03
 *@description <TODO description class purpose>
 *@author 12468
 *@version 1.0.0
 *@create 2024-11-13 22:25
 **/
public class SystemDemo03 {
    public static void main(String[] args) {
        /**
         * 细节：
         *  1. 如果数据源数组和目的数组都是基本数据类型，那么两者的类型必须保持一致，否则报错
         *  2. 再拷贝的时候需要考虑数组的长度，如果超出范围也会报错
         *  3. 如果数据源组和目的数组都是应用数据类型，那么子类类型可以赋值给父类类型
         */
        Student s1 = new Student("zhangsan", 18);
        Student s2 = new Student("lisi", 19);
        Student s3 = new Student("wangwu", 20);

        Student[] arr = {s1, s2, s3};
        Student[] arr1 = new Student[arr.length];
        System.arraycopy(arr, 0, arr1, 0, arr1.length);
        for (Student student : arr1) {
            System.out.println(STR."\{student.getName()} \{student.getAge()}");
        }

        Person[] arr2 = new Person[arr.length];
        System.arraycopy(arr, 0, arr2, 0, arr2.length);
        for (Person person : arr2) {
            System.out.println(person.getName() + " " + person.getAge());
        }
    }
}

class Person {
    private String name;
    private int age;

    public Person() {
    }

    public Person(String name, int age) {
        this.name = name;
        this.age = age;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }
}

class Student extends Person {
    public Student() {
    }

    public Student(String name, int age) {
        super(name, age);
    }

}
